#include<bits/stdc++.h>
using namespace std;
int search(int array[], int low, int high, int target);
int main(){
	int n,i,j;
	cin>>n;
	int a[n],b[n]={0},count=0,flag;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
		for(i=0;i<n;i++){
		flag=search(b, 0, count, a[i]);
		if(flag!=-1) b[flag]=a[i];
		else {
			b[count]=a[i];
			count++;
		}
	}
	cout<<count;
	return 0;
}
int search(int array[], int low, int high, int target)
{
	int mid,flag=0;
    while(low < high)
    {
         mid = (low + high)/2;
        if (array[mid] > target){
			flag=1;
            high= mid-1;
        }
        else if (array[mid] < target)
            low = mid +1;
    }
    if(flag==1) return mid;
    else return -1;
}
